package io.renren.controller;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import io.renren.entity.SysUserEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.EmpArchivesbaseRecordEntity;
import io.renren.service.EmpArchivesbaseRecordService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;


/**
 * 员工档案移交记录表
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-07-14 17:25:56
 */
@RestController
@RequestMapping("emparchivesbaserecord")
public class EmpArchivesbaseRecordController extends AbstractController{
	@Autowired
	private EmpArchivesbaseRecordService empArchivesbaseRecordService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("emparchivesbaserecord:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<EmpArchivesbaseRecordEntity> empArchivesbaseRecordList = empArchivesbaseRecordService.queryList(query);
		int total = empArchivesbaseRecordService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(empArchivesbaseRecordList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("emparchivesbaserecord:info")
	public R info(@PathVariable("id") Integer id){
		EmpArchivesbaseRecordEntity empArchivesbaseRecord = empArchivesbaseRecordService.queryObject(id);
		
		return R.ok().put("empArchivesbaseRecord", empArchivesbaseRecord);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("emparchivesbaserecord:save")
	public R save(@RequestBody EmpArchivesbaseRecordEntity empArchivesbaseRecord){
		empArchivesbaseRecordService.save(empArchivesbaseRecord);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("emparchivesbaserecord:update")
	public R update(@RequestBody EmpArchivesbaseRecordEntity empArchivesbaseRecord){
		empArchivesbaseRecordService.update(empArchivesbaseRecord);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	//@RequiresPermissions("emparchivesbaserecord:delete")
	public R delete(@RequestBody Integer[] ids){
		empArchivesbaseRecordService.deleteBatch(ids);
		
		return R.ok();
	}

	/**
	 * 添加档案异动数据
	 * @return
	 */
	@RequestMapping("/archConfirm")
	//@RequiresPermissions("emparchivesbaserecord:update")
	public R archConfirm(@RequestBody JSONObject jsonObject){
		SysUserEntity user = getUser();
		jsonObject.put("user",user);
		String res = empArchivesbaseRecordService.archConfirm(jsonObject);
		if (res==null)
			return R.ok();
		else
			return R.ok().put("code",1).put("msg","用户"+res+"需要先提交档案才能发起档案异动");
	}


	
}
